package com.ruoyi.web.controller.lucky;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lucky.domain.TTakeover;
import com.ruoyi.lucky.service.ITTakeoverService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品取货Controller
 * 
 * @author ruoyi
 * @date 2020-11-12
 */
@Controller
@RequestMapping("/lucky/takeover")
public class TTakeoverController extends BaseController
{
    private String prefix = "lucky/takeover";

    @Autowired
    private ITTakeoverService tTakeoverService;

    @RequiresPermissions("lucky:takeover:view")
    @GetMapping()
    public String takeover()
    {
        return prefix + "/takeover";
    }

    /**
     * 查询商品取货列表
     */
    @RequiresPermissions("lucky:takeover:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TTakeover tTakeover)
    {
        startPage();
        List<TTakeover> list = tTakeoverService.selectTTakeoverList(tTakeover);
        return getDataTable(list);
    }

    /**
     * 导出商品取货列表
     */
    @RequiresPermissions("lucky:takeover:export")
    @Log(title = "商品取货", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TTakeover tTakeover)
    {
        List<TTakeover> list = tTakeoverService.selectTTakeoverList(tTakeover);
        ExcelUtil<TTakeover> util = new ExcelUtil<TTakeover>(TTakeover.class);
        return util.exportExcel(list, "takeover");
    }

    /**
     * 新增商品取货
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品取货
     */
    @RequiresPermissions("lucky:takeover:add")
    @Log(title = "商品取货", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TTakeover tTakeover)
    {
        return toAjax(tTakeoverService.insertTTakeover(tTakeover));
    }

    /**
     * 修改商品取货
     */
    @GetMapping("/edit/{toId}")
    public String edit(@PathVariable("toId") Long toId, ModelMap mmap)
    {
        TTakeover tTakeover = tTakeoverService.selectTTakeoverById(toId);
        mmap.put("tTakeover", tTakeover);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品取货
     */
    @RequiresPermissions("lucky:takeover:edit")
    @Log(title = "商品取货", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TTakeover tTakeover)
    {
        return toAjax(tTakeoverService.updateTTakeover(tTakeover));
    }

    /**
     * 删除商品取货
     */
    @RequiresPermissions("lucky:takeover:remove")
    @Log(title = "商品取货", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tTakeoverService.deleteTTakeoverByIds(ids));
    }
}
